package com.wh.basic.conroller;

import com.wh.basic.dto.LoginDto;
import com.wh.basic.vo.AjaxResult;
import com.wh.user.dto.WxBinderDto;
import com.wh.user.service.ILoginInfoService;
import com.wh.user.service.IWxuserService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginInfoService loginInfoService;
    @Autowired
    private IWxuserService wxuserService;

    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody LoginDto loginDto) {
        Map<String, Object> map = loginInfoService.accountLogin(loginDto);
        return AjaxResult.me().setResultObj(map);
    }

    /**
     * 微信登录
     *
     * @return
     */
    @GetMapping("wechat/{code}")
    public AjaxResult weChatLogin(@PathVariable String code) {
        try {
            return loginInfoService.weChatLogin(code);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后重试!!!");
        }
    }

    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WxBinderDto binderDto) {
        return wxuserService.wechatBinder(binderDto);
    }

}
